Skip to content

Conversation

@msakai
Copy link
Contributor

@msakai msakai commented Oct 23, 2025

Contributor Agreements

Please read the contributor agreements and if you agree, please click the checkbox below.

  • I agree to the contributor agreements.

Tip

Please follow the Quick TODO list to smoothly merge your PR.

Motivation

Fix the following mypy errors of the value_at_risk package.

package/samplers/value_at_risk/_gp/acqf.py:192: error: "GPRegressor" has no attribute "joint_posterior"  [attr-defined]
package/samplers/value_at_risk/sampler.py:126: error: Incompatible types in assignment (expression has type "Callable[[optuna._gp.gp.GPRegressor], Tensor]", variable has type "Callable[[value_at_risk._gp.gp.GPRegressor], Tensor]")  [assignment]
package/samplers/value_at_risk/sampler.py:183: error: Argument 1 to "optimize_acqf_mixed" has incompatible type "value_at_risk._gp.acqf.BaseAcquisitionFunc"; expected "optuna._gp.acqf.BaseAcquisitionFunc"  [arg-type]
package/samplers/value_at_risk/sampler.py:286: error: Argument "gpr" to "ValueAtRisk" has incompatible type "value_at_risk._gp.gp.GPRegressor"; expected "optuna._gp.gp.GPRegressor"  [arg-type]
package/samplers/value_at_risk/sampler.py:297: error: Argument "gpr" to "ConstrainedLogValueAtRisk" has incompatible type "value_at_risk._gp.gp.GPRegressor"; expected "optuna._gp.gp.GPRegressor"  [arg-type]
package/samplers/value_at_risk/sampler.py:299: error: Argument "constraints_gpr_list" to "ConstrainedLogValueAtRisk" has incompatible type "list[value_at_risk._gp.gp.GPRegressor]"; expected "list[optuna._gp.gp.GPRegressor]"  [arg-type]
package/samplers/value_at_risk/sampler.py:307: error: Argument 11 to "ConstrainedLogValueAtRisk" has incompatible type "**dict[str, Tensor]"; expected "float"  [arg-type]
package/samplers/value_at_risk/tests/test_samplers.py:12: error: Cannot find implementation or library stub for module named "_pytest.fixtures"  [import-not-found]
package/samplers/value_at_risk/tests/test_samplers.py:13: error: Cannot find implementation or library stub for module named "_pytest.mark.structures"  [import-not-found]
package/samplers/value_at_risk/tests/test_samplers.py:13: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
package/samplers/value_at_risk/tests/test_samplers.py:28: error: Cannot find implementation or library stub for module named "pytest"  [import-not-found]
package/samplers/value_at_risk/tests/test_samplers.py:287: error: "BaseDistribution" has no attribute "step"  [attr-defined]
package/samplers/value_at_risk/tests/test_samplers.py:287: error: "BaseDistribution" has no attribute "log"  [attr-defined]
package/samplers/value_at_risk/tests/test_samplers.py:288: error: "BaseDistribution" has no attribute "step"  [attr-defined]
package/samplers/value_at_risk/tests/test_samplers.py:288: error: "BaseDistribution" has no attribute "log"  [attr-defined]
Found 14 errors in 3 files (checked 7 source files)

Regarding errors related to GPRegressor and BaseAcquisitionFunc, this fix is merely an ad hoc suppression of errors using cast. To fix the problem fundamentally, we have to decide whether to use Optuna's classes or our own versions.

Description of the changes

TODO List towards PR Merge

Please remove this section if this PR is not an addition of a new package.
Otherwise, please check the following TODO list:

  • Copy ./template/ to create your package
  • Replace <COPYRIGHT HOLDER> in LICENSE of your package with your name
  • Fill out README.md in your package
  • Add import statements of your function or class names to be used in __init__.py
  • (Optional) Add from __future__ import annotations at the head of any Python files that include typing to support older Python versions
  • Apply the formatter based on the tips in README.md
  • Check whether your module works as intended based on the tips in README.md

@msakai msakai marked this pull request as draft October 23, 2025 01:46
@msakai msakai force-pushed the fix-value-at-risk-mypy-errors branch from da19131 to 247f945 Compare October 24, 2025 02:41
@msakai msakai marked this pull request as ready for review October 24, 2025 02:45
@c-bata c-bata self-assigned this Nov 7, 2025
Copy link
Member

@c-bata c-bata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that all mypy checks have been passed. LGTM!

@c-bata c-bata merged commit 0845269 into optuna:main Nov 10, 2025
3 checks passed
@msakai msakai deleted the fix-value-at-risk-mypy-errors branch November 11, 2025 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants